local skill = fk.CreateSkill{
  name = "tea__zhidai_active",
}
---@type ActiveSkillSpec
local zhidai_active = {
  anim_type = "drawcard",
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(skill.name, Player.HistoryPhase) == 0
  end, 
  on_use = function(self, room, effect)
    local player = effect.from
    player:drawCards(1, "tea__zhidai")
    for i = 1, 100 do
      if not player:isKongcheng() then
        if table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id).color ~= Fk:getCardById(player:getCardIds("h")[1]).color
        end) then break end
      end
      player:drawCards(1, "tea__zhidai")
    end
    player:showCards(player:getCardIds("h"))
    local redc = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local blackc = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    local mark = {}
    if #redc <= #blackc then
      table.insert(mark, "zhidai_red_viewas")
    end
    if #redc >= #blackc then
      table.insert(mark, "zhidai_black_viewas")
    end
    if #mark > 0 then
      room:setPlayerMark(player, "@tea__zhidai_mark-phase", mark)
      room:handleAddLoseSkills(player, "tea__zhidai&", skill.name, false, false)
      room.logic:getCurrentEvent():findParent(GameEvent.Phase):addCleaner(function()
        room:handleAddLoseSkills(player, "-tea__zhidai&", nil, false, false)
      end)
    end
  end,
}
skill:addEffect("active", zhidai_active)
return skill